package com.tinusgraglin.enclusiv.ui.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.tinusgraglin.enclusiv.Util
import com.tinusgraglin.enclusiv.datalayer.repos.UserRepo
import kotlinx.coroutines.Deferred

class SignUpActivityViewModel (
    private val userRepo: UserRepo
) : ViewModel() {

    fun verifyEmailAsync(email: String): Deferred<Unit> =
        Util.requestWithDeferredResultAsync(viewModelScope) {
            userRepo.sendVerificationCodeToEmail(email)
        }

    fun verifyCodeAsync(email: String, code: String): Deferred<Boolean> =
        Util.requestWithDeferredResultAsync(viewModelScope) {
            userRepo.checkVerificationCode(email, code)
        }

    fun registerAsync(email: String, password: String) =
        Util.requestWithDeferredResultAsync(viewModelScope) {
            userRepo.register(email, password)
        }
}